package conexion;
import com.google.gson.Gson;
import com.google.gson.JsonObject;


public class JsonParse {
		
	
	static String itemId (String json, int indice){
		
        JsonObject jobj = new Gson().fromJson(json, JsonObject.class);
        JsonObject jsonAuctionInfo = (JsonObject) jobj.get("auctionInfo").getAsJsonArray().get(indice);
        JsonObject jsonItemData =  (JsonObject) jsonAuctionInfo.get("itemData");		
        String itemId = jsonItemData.get("id").toString();        
		return itemId;
	}
	
	static int startingBid (String json, int indice){
		
        JsonObject jobj = new Gson().fromJson(json, JsonObject.class);
        JsonObject jsonAuctionInfo = (JsonObject) jobj.get("auctionInfo").getAsJsonArray().get(indice);
        String Bid = jsonAuctionInfo.get("startingBid").toString();		
        int startingBid = Integer.parseInt(Bid);
		return startingBid;
	}
	
	static int discardValue (String json, int indice){
		
        JsonObject jobj = new Gson().fromJson(json, JsonObject.class);
        JsonObject jsonAuctionInfo = (JsonObject) jobj.get("auctionInfo").getAsJsonArray().get(indice);
        JsonObject jsonItemData =  (JsonObject) jsonAuctionInfo.get("itemData");		      
        String discard = jsonItemData.get("discardValue").toString();
        int discardValue = Integer.parseInt(discard);
		return discardValue;
	}
	
	static int currentBid (String json, int indice){
		
        JsonObject jobj = new Gson().fromJson(json, JsonObject.class);
        JsonObject jsonAuctionInfo = (JsonObject) jobj.get("auctionInfo").getAsJsonArray().get(indice);	      
        String bid = jsonAuctionInfo.get("currentBid").toString();
        int currentBid = Integer.parseInt(bid);
		return currentBid;
	}
	
	static String tradeId (String json, int indice){
		
        JsonObject jobj = new Gson().fromJson(json, JsonObject.class);      
        JsonObject jsonAuctionInfo = (JsonObject) jobj.get("auctionInfo").getAsJsonArray().get(indice);       
        String tradeId = jsonAuctionInfo.get("tradeId").toString();		
		
		return tradeId;
	}

	static String stadoTradeId (String json){
		
        JsonObject jobj = new Gson().fromJson(json, JsonObject.class);      
        JsonObject jsonAuctionInfo = (JsonObject) jobj.get("auctionInfo").getAsJsonArray().get(0);       
        String stadoTradeId = jsonAuctionInfo.get("tradeId").toString();		
		
		return stadoTradeId;
	}
	
	static String watchlist (String json, int indice){
		
        JsonObject jobj = new Gson().fromJson(json, JsonObject.class);
        JsonObject jsonAuctionInfo = (JsonObject) jobj.get("auctionInfo").getAsJsonArray().get(indice);
        JsonObject jsonItemData =  (JsonObject) jsonAuctionInfo.get("itemData");		
        String itemId = jsonItemData.get("id").toString(); 
        
		return itemId;
	}
	
	static String tradeState (String json, int indice){
		
        JsonObject jobj = new Gson().fromJson(json, JsonObject.class);
        JsonObject jsonAuctionInfo = (JsonObject) jobj.get("auctionInfo").getAsJsonArray().get(indice);
        String tradeState = jsonAuctionInfo.get("tradeState").toString();		 
        
		return tradeState;
	}
	
	static int expires (String json, int indice){
		
        JsonObject jobj = new Gson().fromJson(json, JsonObject.class);
        JsonObject jsonAuctionInfo = (JsonObject) jobj.get("auctionInfo").getAsJsonArray().get(indice);
        String expiresStr = jsonAuctionInfo.get("expires").toString();		 
        int expires = Integer.parseInt(expiresStr);
		return expires;
	}
	
	static int buyNowPrice (String json, int indice){
		
        JsonObject jobj = new Gson().fromJson(json, JsonObject.class);
        JsonObject jsonAuctionInfo = (JsonObject) jobj.get("auctionInfo").getAsJsonArray().get(indice);
        String buyNowPriceStr = jsonAuctionInfo.get("buyNowPrice").toString();		 
        int buyNowPrice = Integer.parseInt(buyNowPriceStr);
		return buyNowPrice;
	}
	
	static String resourceId (String json, int indice){
		
        JsonObject jobj = new Gson().fromJson(json, JsonObject.class);
        JsonObject jsonAuctionInfo = (JsonObject) jobj.get("auctionInfo").getAsJsonArray().get(indice);
        JsonObject jsonItemData =  (JsonObject) jsonAuctionInfo.get("itemData");		
        String resourceId = jsonItemData.get("resourceId").toString(); 
        
		return resourceId;
	}
	
	static String bidState (String json, int indice){
		
        JsonObject jobj = new Gson().fromJson(json, JsonObject.class);
        JsonObject jsonAuctionInfo = (JsonObject) jobj.get("auctionInfo").getAsJsonArray().get(indice);
        String bidState = jsonAuctionInfo.get("bidState").toString();		 
        
		return bidState;
	}
	
	static String itemIdPurchase (String json, int indice){
		
        JsonObject jobj = new Gson().fromJson(json, JsonObject.class);
        JsonObject jsonAuctionInfo = (JsonObject) jobj.get("itemData").getAsJsonArray().get(indice);
        String itemIdPurchase = jsonAuctionInfo.get("id").toString();		 
        
		return itemIdPurchase;
	}
}
